<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Dish>
 */
class DishFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $tags = ['经典', '推荐', '热销', '新品', '特色', '家常', '下饭', '清淡', '麻辣', '微辣'];

        return [
            'name' => fake()->words(2, true),
            'description' => fake()->sentence(10),
            'category_id' => fake()->numberBetween(1, 7), // 对应7个分类
            'image' => fake()->imageUrl(400, 300, 'food'),
            'tags' => fake()->randomElements($tags, fake()->numberBetween(1, 3)),
            'flavors' => fake()->randomElements(['麻辣', '微辣', '清淡', '酸甜', '咸鲜', '香辣'], fake()->numberBetween(1, 2)),
            'cooking_time' => fake()->numberBetween(5, 60),
            'is_available' => fake()->boolean(90), // 90%概率可用
            'is_featured' => fake()->boolean(20), // 20%概率推荐
            'sort_order' => fake()->numberBetween(1, 100),
            'view_count' => fake()->numberBetween(0, 1000),
            'order_count' => fake()->numberBetween(0, 500),
        ];
    }

    /**
     * 推荐菜品
     */
    public function featured(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_featured' => true,
        ]);
    }

    /**
     * 可用菜品
     */
    public function available(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_available' => true,
        ]);
    }

    /**
     * 热菜
     */
    public function hot(): static
    {
        return $this->state(fn (array $attributes) => [
            'category_id' => 1,
            'flavors' => ['麻辣', '香辣'],
        ]);
    }

    /**
     * 凉菜
     */
    public function cold(): static
    {
        return $this->state(fn (array $attributes) => [
            'category_id' => 2,
            'flavors' => ['清淡', '酸甜'],
        ]);
    }
}
